package com.njuptB180316.boki.dao;

import com.njuptB180316.boki.dataobject.User;
import java.util.List;

import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

@Mapper
public interface UserMapper {
    @Delete({
        "delete from user",
        "where phone = #{phone,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long phone);

    @Insert({
        "insert into user (phone, name, ",
        "password, authority)",
        "values (#{phone,jdbcType=BIGINT}, #{name,jdbcType=VARCHAR}, ",
        "#{password,jdbcType=VARCHAR}, #{authority,jdbcType=INTEGER})"
    })
    int insert(User record);

    @Select({
        "select",
        "phone, name, password, authority",
        "from user",
        "where phone = #{phone,jdbcType=BIGINT}"
    })
    @Results({
        @Result(column="phone", property="phone", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
        @Result(column="password", property="password", jdbcType=JdbcType.VARCHAR),
        @Result(column="authority", property="authority", jdbcType=JdbcType.INTEGER)
    })
    User selectByPrimaryKey(Long phone);

    @Select({
        "select",
        "phone, name, password, authority",
        "from user"
    })
    @Results({
        @Result(column="phone", property="phone", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
        @Result(column="password", property="password", jdbcType=JdbcType.VARCHAR),
        @Result(column="authority", property="authority", jdbcType=JdbcType.INTEGER)
    })
    List<User> selectAll();

    @Update({
        "update user",
        "set name = #{name,jdbcType=VARCHAR},",
          "password = #{password,jdbcType=VARCHAR},",
          "authority = #{authority,jdbcType=INTEGER}",
        "where phone = #{phone,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(User record);
}